//
//  YSLMainNavigationController.swift
//  SinaWeibo
//
//  Created by 嵩雷 on 16/3/6.
//  Copyright © 2016年 嵩雷. All rights reserved.
//

import UIKit

class YSLMainNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count > 0 {
            
            var title = "返回"
            
            if childViewControllers.count == 1 {
//                添加第二个控制器
                title = childViewControllers.first?.title ?? "返回"
            }
//            跳到第二个控制器隐藏底部tabBar
            viewController.hidesBottomBarWhenPushed = true
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: "navigationbar_back_withtext", title: title, target: self, action: "back")
        }
        super.pushViewController(viewController, animated: animated)
    }
    
   private func back() {
        popViewControllerAnimated(true)
    }
}
